package com.qfjy.controller;

import com.qfjy.entity.Medal;
import com.qfjy.service.MedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
public class MedalController {
    @Autowired
    private MedalService medalService;

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("index")
    public String index() {
        return "index";
    }

    @RequestMapping("getMedalNum")
    public String getMedalNum(Model model) {
        List<Medal> medal = medalService.getMedal();
        model.addAttribute("medal", medal);
        restTemplate.getForObject(null,null,null,null);
        return "index";
    }

    @PostMapping("add")
    public String add(String country, String pai) {
        medalService.add(country, pai);
        return "redirect:/getMedalNum";
    }

}
